package qlsl.androiddesign.view.subview.activityview;

import com.qlsl.androiddesign.kuaiwa.R;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import qlsl.androiddesign.activity.subactivity.OrderDetailActivity;
import qlsl.androiddesign.activity.subactivity.ShoppingDetailActivity;
import qlsl.androiddesign.entity.otherentity.ShoppingDetail;
import qlsl.androiddesign.util.commonutil.ImageUtils;
import qlsl.androiddesign.util.commonutil.TextSizeUtils;
import qlsl.androiddesign.util.commonutil.TimeFormatUtils;
import qlsl.androiddesign.util.runfeng.ToActivityUtil;
import qlsl.androiddesign.view.baseview.FunctionView;

/**
 * 订单详情页<br/>
 * 需要传入的键：data,isBusiness<br/>
 * 传入的值类型：ShoppingDetail,boolean <br/>
 * 传入的值含义：订单详情,是否为商家<br/>
 * 是否必传 ：是，否
 */
public class OrderDetailView extends FunctionView<OrderDetailActivity> {

	public OrderDetailView(OrderDetailActivity activity) {
		super(activity);
		setContentView(R.layout.activity_order_detail);
	}

	protected void initView(View view) {
		setTitle("订单详情");
		boolean isBusiness = activity.getIntent().getBooleanExtra("isBusiness", false);
		if (isBusiness) {
			((TextView) findViewById(R.id.tv_contact)).setText("联系买家");
		} else {
			((TextView) findViewById(R.id.tv_contact)).setText("联系卖家");
		}
	}

	protected void initData() {
		setOrderDetailData();
	}

	protected void initListener() {

	}

	public <T> void showData(T... t) {

	}

	public <T> void showNoData(T... t) {

	}

	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.tv_contact:
			doClickPhoneNumberView();
			break;
		case R.id.iv_icon:
			doClickIconView(view);
			break;
		}
	}

	private void doClickPhoneNumberView() {
		ShoppingDetail item = (ShoppingDetail) activity.getIntent().getSerializableExtra("data");
		boolean isBusiness = activity.getIntent().getBooleanExtra("isBusiness", false);
		if (isBusiness) {
			String mobile = item.getBuyerno();
			if (!TextUtils.isEmpty(mobile)) {
				ToActivityUtil.callPhoneActivity(activity, mobile);
			} else {
				showToast("买家未提供电话号码");
			}
		} else {
			String mobile = item.getBusinessmobile();
			if (!TextUtils.isEmpty(mobile)) {
				ToActivityUtil.callPhoneActivity(activity, mobile);
			} else {
				showToast("卖家未提供电话号码");
			}
		}

	}

	private void doClickIconView(View view) {
		ShoppingDetail item = (ShoppingDetail) activity.getIntent().getSerializableExtra("data");
		startActivity(item, ShoppingDetailActivity.class);
	}

	private void setOrderDetailData() {
		ShoppingDetail item = (ShoppingDetail) activity.getIntent().getSerializableExtra("data");
		ImageView iv_icon = findViewById(R.id.iv_icon);
		TextView tv_name = findViewById(R.id.tv_name);
		TextView tv_num = findViewById(R.id.tv_num);
		TextView tv_price_sell = findViewById(R.id.tv_price_sell);
		TextView tv_price_src = findViewById(R.id.tv_price_src);
		TextView tv_state = findViewById(R.id.tv_state);
		TextView tv_total_num = findViewById(R.id.tv_total_num);
		TextView tv_total_price = findViewById(R.id.tv_total_price);
		TextView tv_username = findViewById(R.id.tv_username);
		TextView tv_phone = findViewById(R.id.tv_phone);
		TextView tv_address = findViewById(R.id.tv_address);
		TextView tv_time = findViewById(R.id.tv_time);

		String name = item.getGoodsname();
		String price_new = "价格：￥" + item.getNewprice();
		String price_old = "￥" + item.getOldprice();
		String num = item.getNums();
		String state = item.getState();
		if (state.equals("0")) {
			tv_state.setText("未支付");
		} else if (state.equals("1")) {
			tv_state.setText("已支付");
		}

		ImageUtils.rectOri(activity, item.getPhoto(), iv_icon);
		tv_name.setText(name);
		tv_num.setText("数量：" + num + "件");
		TextSizeUtils.setText(tv_price_sell, price_new, 3, price_new.length(), 14,
				activity.getResources().getColor(R.color.half_red));
		tv_price_src.setText(price_old);
		TextSizeUtils.setTextCenterLine(tv_price_src);
		tv_total_num.setText("共" + num + "件商品 ");
		tv_total_price.setText("合计：" + item.getPrice() + "元");
		tv_username.setText(item.getConsigneename());
		tv_phone.setText(item.getConsigneemobile());
		tv_address.setText(item.getConsigneeaddress());
		tv_time.setText("下单时间：" + TimeFormatUtils.format(item.getTime()));
	}

}
